package com.admin.business.voteUser;

import com.alibaba.druid.util.StringUtils;
import com.admin.business.voteEssentialInformation.VoteEssentialInformationDao;
import com.admin.business.voteEssentialInformation.VoteEssentialInformationService;
import com.admin.business.voteOrgInfo.VoteOrgInfoDao;
import com.admin.business.voteRecommend.VoteRecommendDao;
import com.admin.business.voteRecord.VoteRecordDao;
import com.admin.utils.FileExportImportUtil;
import com.admin.utils.UserCardInfoUtil;
import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @description: 投票用户认证
 * @create: 2022-07-08 19:04:49
 **/
@Service("voteUser")
@Slf4j
public class VoteUserService {

    @Resource
    VoteUserDao voteUserDao;

    @Resource
    VoteRecommendDao voteRecommendDao;

    @Resource
    VoteEssentialInformationService voteEssentialInformationService;

    @Resource
    VoteOrgInfoDao voteOrgInfoDao;

    //---------------------------------2022-11-09，代码重构-------------------------------
    /**
     * 删除谈判小组
     * @return
     */
    @OpenApi
    public Return delNegotiatingTeam(CDO cdoRequest){
        String id = cdoRequest.getString("id");
        if(StringUtils.isEmpty(id)){
            return Return.valueOf(-2,"id不可为空");
        }
        voteUserDao.delNegotiatingTeamById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 谈判小组，人员数量查询
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getNegotiatingTeamNumber(CDO cdoRequest){
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if(StringUtils.isEmpty(essential_information_id)){
            return Return.valueOf(-2,"essential_information_id不可为空");
        }
        CDO selectMember = new CDO();
        selectMember.set("essential_information_id",essential_information_id);
        selectMember.set("whether_negotiation_team",1);
        selectMember.set("members_state",1);
        int memberTotal = voteUserDao.getVoteUserListCount(selectMember);
        CDO selectNeighborhood = new CDO();
        selectNeighborhood.set("essential_information_id",essential_information_id);
        selectNeighborhood.set("whether_negotiation_team",1);
        selectNeighborhood.set("whether_neighborhood",1);
        int neighborhoodTotal = voteUserDao.getVoteUserListCount(selectNeighborhood);
        CDO selectExperts = new CDO();
        selectExperts.set("essential_information_id",essential_information_id);
        selectExperts.set("whether_negotiation_team",1);
        selectExperts.set("whether_experts",1);
        int expertsTotal = voteUserDao.getVoteUserListCount(selectExperts);
        CDO selectOwner = new CDO();
        selectOwner.set("essential_information_id",essential_information_id);
        selectOwner.set("whether_negotiation_team",1);
        selectOwner.set("whether_owner",1);
        int ownerTotal = voteUserDao.getVoteUserListCount(selectOwner);
        cdoRequest.set("memberTotal",memberTotal);//委员
        cdoRequest.set("neighborhoodTotal",neighborhoodTotal);//街道社区
        cdoRequest.set("expertsTotal",expertsTotal);//专家
        cdoRequest.set("ownerTotal",ownerTotal);//业主
        return Return.valueOf(cdoRequest);
    }





    /**
     * 添加或修改谈判小组成员信息
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return addOrUpdateNegotiatingTeam(CDO cdoRequest){
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if(StringUtils.isEmpty(essential_information_id)){
            return Return.valueOf(-2,"essential_information_id不可为空");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if (voteInfo == null){
            return Return.valueOf(-2, "表决信息异常");
        }
        String full_name = cdoRequest.getString("full_name");
        String telephone = cdoRequest.getString("telephone");
        String company = cdoRequest.getString("company");
        if(StringUtils.isEmpty(full_name) || StringUtils.isEmpty(telephone) || StringUtils.isEmpty(company)){
            return Return.valueOf(-2,"请填写完整人员信息");
        }
        //添加人是否为助业网会员
        //添加委员的用户id
        String userId = voteEssentialInformationService.getUserIdByUserNameAndTel(full_name, telephone);
        if(StringUtils.isEmpty(userId)){
            return Return.valueOf(-2,"该用户未注册助业网会员，请先注册！");
        }
        //添加谈判小组，已经是小组成员，不可再次添加
        CDO publicCount = new CDO();
        publicCount.set("essential_information_id", essential_information_id);
        publicCount.set("user_id", userId);
        CDO voteUserInfo = voteUserDao.getVoteUserInfoByCDO(publicCount);
        String id = cdoRequest.getString("id");//编辑标识参数
        if(voteUserInfo != null && StringUtils.isEmpty(id)){
            String whether_negotiation_team = voteUserInfo.getString("whether_negotiation_team");
            if("1".equals(whether_negotiation_team)){
                return Return.valueOf(-2,"该人已为谈判小组成员，请勿再次添加");
            }
        }
        cdoRequest.set("user_id", userId);
        cdoRequest.set("user_id_zyw", userId);
        cdoRequest.set("house_name", voteInfo.getString("community_name"));//小区名称  无意义参数
        voteEssentialInformationService.publicAdditionsAddOrUpdateVoteUser(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 工作组投票判断当前时间是否可投票
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return getTimeDiffByTime(CDO cdoRequest){
        Date time = cdoRequest.getDate("time");
        if(time == null){
            return  Return.valueOf(-2,"time不可为空");
        }
        //time 格式 yyyy-MM-dd HH:mm:ss
        Integer timeState = 0;//0.
        if(new Date().getTime() <= time.getTime()){

        }

        return Return.SUCCESS;
    }


    /**
     * 业主端选聘物业公司投票
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return ownerAppOrgVote(CDO cdoRequest){
        String id = cdoRequest.getString("id");
        if(StringUtils.isEmpty(id)) return Return.valueOf(-2, "被投票对象主键id不可为空");
        //操作人
        String user_id = cdoRequest.getString("user_id");
        if(StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "操作人id不可为空");
        CDO voteOrgInfo = voteOrgInfoDao.getVoteOrgInfoById(Integer.parseInt(id));
        if(voteOrgInfo == null) return Return.valueOf(-2, "物业公司信息异常");
        //添加投票记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("vote_user_id",id);
        addVoteRecord.set("essential_information_id",voteOrgInfo.getString("p_id"));
        addVoteRecord.set("vote_user",user_id);
        addVoteRecord.set("user_building_number",cdoRequest.getString("user_building_number"));
        addVoteRecord.set("user_name",cdoRequest.getString("user_name"));
        //推举状态：1、筹备组推举，2、委员推举
        addVoteRecord.set("recommend_state",cdoRequest.getString("voteType"));
        voteRecommendDao.addVoteRecommend(addVoteRecord);
        //修改被投票公司信息投票数量+1
        CDO updateVoteInfo = new CDO();
        updateVoteInfo.set("id",id);
        voteUserDao.updateOrgNumberOfVotes(updateVoteInfo);
        return Return.SUCCESS;
    }



    /**
     * 业主app投票（人）
     * @param cdoRequest
     * @return
     */
    @OpenApi
    public Return ownerAppVote(CDO cdoRequest){
        //被投票对象主键id
        String id = cdoRequest.getString("id");
        if(StringUtils.isEmpty(id)) return Return.valueOf(-2, "被投票对象主键id不可为空");
        //被投人信息
        CDO voteUser = voteUserDao.getVoteUserById(Integer.parseInt(id));
        if(voteUser == null) return Return.valueOf(-2, "被投票对象异常，请稍后再试");
        //操作人
        String user_id = cdoRequest.getString("user_id");
        if(StringUtils.isEmpty(user_id)) return Return.valueOf(-2, "操作人id不可为空");
        //添加投票记录
        CDO addVoteRecord = new CDO();
        addVoteRecord.set("vote_user_id",id);
        addVoteRecord.set("essential_information_id",voteUser.getString("essential_information_id"));
        addVoteRecord.set("vote_user",user_id);
        addVoteRecord.set("user_building_number",cdoRequest.getString("user_building_number"));
        addVoteRecord.set("user_name",cdoRequest.getString("user_name"));
        //推举状态：1、筹备组推举，2、委员推举
        addVoteRecord.set("recommend_state",cdoRequest.getString("voteType"));
        voteRecommendDao.addVoteRecommend(addVoteRecord);
        //修改被投票人信息投票数量+1
        CDO updateUserVoteInfo = new CDO();
        updateUserVoteInfo.set("voteType",cdoRequest.getString("voteType"));
        updateUserVoteInfo.set("id",id);
        voteUserDao.updateUserNumberOfVotes(updateUserVoteInfo);
        return Return.SUCCESS;
    }




    /**
     * 校验是否为系统用户
     * @param user_id
     * @return
     */
    public boolean verifyWhetherSysUser(Long user_id) {
        if(user_id == null){
            return false;
        }
        CDO userInfo = voteUserDao.getPersonalInformationCdo(user_id);//有信息就是
        return userInfo != null ? true :false;
    }




    //    查询身份证年龄 和楼宇这个用于回显信息
    @OpenApi
    public Return getvoteUserPersonnelInformation(CDO cdoRequest) {


        Long user_id = cdoRequest.getLong("userId");

        CDO personalInformationCdo = voteUserDao.getPersonalInformationCdo(user_id);
        if (personalInformationCdo == null) {
            return Return.valueOf(-3, "未查询改人员信息");
        }
//       根据当前user_id拿楼宇信息

        List<CDO> venusUserOwnerBuilding = voteUserDao.getVenusUserOwnerBuilding(user_id.toString());
        if (venusUserOwnerBuilding.size() > 0) {
            for (int i = 0; i < venusUserOwnerBuilding.size(); i++) {
                personalInformationCdo.set("doorCode", venusUserOwnerBuilding.get(i).getString("buildDistrictCode")
                        + "-" + venusUserOwnerBuilding.get(i).getString("buildTowerCode") + "-" + venusUserOwnerBuilding.get(i).getString("roomUnitNumber")
                        + "-" + venusUserOwnerBuilding.get(i).getString("roomCode"));
                personalInformationCdo.set("area", venusUserOwnerBuilding.get(i).getString("roomAreaOfStructure"));//面积
                personalInformationCdo.set("one_district", venusUserOwnerBuilding.get(i).getString("buildDistrictCode"));//区号
                personalInformationCdo.set("one_floor", venusUserOwnerBuilding.get(i).getString("buildTowerCode"));//楼号
                personalInformationCdo.set("one_unit", venusUserOwnerBuilding.get(i).getString("roomUnitNumber"));//单元
                personalInformationCdo.set("one_house_number", venusUserOwnerBuilding.get(i).getString("roomCode"));//门牌号
            }
        }


//        根据身份证号获取当前人员信息
        String id_card = personalInformationCdo.getString("user_card_code");
        if (id_card != null) {
            Map<String, String> birAgeSex = userCardInfoUtil.getBirAgeSex(id_card);
            personalInformationCdo.set("birthday", birAgeSex.get("birthday"));//出生日期
            personalInformationCdo.set("age", birAgeSex.get("age"));//年龄
            personalInformationCdo.set("sexCode", birAgeSex.get("sexCode"));//性别
        }


        return Return.valueOf(personalInformationCdo);
    }



    //    调用身份证工作类
    @Autowired
    private UserCardInfoUtil userCardInfoUtil;



    @Resource
    VoteEssentialInformationDao voteEssentialInformationDao;

//    FORMATTER
//    第二步点击查询 打印导出 附议人员信息
    @OpenApi
    public Return getExportAssociates(CDO cdoRequest) throws IOException, ParseException {
        String essential_information_id = cdoRequest.getString("essential_information_id");
        if (StringUtils.isEmpty(essential_information_id)) {
            return Return.valueOf(-2, "未获取到当前信息id");
        }
        CDO voteInfo = voteEssentialInformationDao.getVoteEssentialInformationById(Integer.parseInt(essential_information_id));
        if(voteInfo == null) return Return.valueOf(-2, "表决信息异常");
        List<CDO> voteEssentialInformationList = voteUserDao.getVoteUserList(cdoRequest);
        Date currTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String time = formatter.format(currTime);//导出时间
        String SecondedName  =voteInfo.getString("community_name")+"附议人员投票列表";//投票名称
        String url =FileExportImportUtil.uploadSupportingOfficerFile(voteEssentialInformationList,time,SecondedName);
        CDO result = new CDO();
        result.set("data",url);
        return Return.valueOf(result);
    }


//     第三修改状态

    @OpenApi
    public Return updateVoteChangeStatus(CDO cdoRequest) {

        Long id = cdoRequest.getLong("id");
        if (id == null) {
            return Return.valueOf(-1, "未获取到id,voteStatus");
        }
        voteUserDao.updateVoteChangeStatus(cdoRequest);
        return Return.SUCCESS;
    }


    /**
     * 添加投票用户认证,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_zyw:用户id
     *                   - essential_information_id:基本数据id
     *                   - id_card_just:身份证正面
     *                   - id_card_back:身份证反面
     *                   - house_certificate:房产证
     *                   - housing_area:房屋面积
     *                   - building_number:楼号
     *                   - audit_status:认证状态：0、认证成功，1、取消认证；
     *                   - audit_content:取消认证原因
     *                   - preparation_enroll:筹备组是否报名：1已报名，0未报名
     *                   - preparation_time:筹备组报名时间
     *                   - preparation_total:筹备组报名后总票数
     *                   - preparation_status:是否筹备组成员：1是，0否
     *                   - reconsideration_status:召开附议状态：0、待发起 ，1、已经复议，2、未复议
     *                   - reconsideration_time:召开附议时间
     *                   - user_nation:民族
     *                   - user_olitical_outlook:政治面貌
     *                   - user_declaration:个人宣言
     *                   - user_coronal_photograph_img:冠冕照
     *                   - user_consumption_proof_img:消费证明
     *                   - user_other_img:其他材料
     *                   - committee_member_reason:取消原因
     *                   - committee_member_status:是否报名委员：1已报名，0未报名，2取消资格
     *                   - committee_member_total:委员选拔总票数
     *                   - committee_member_total_offline:线下投票人数
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
//    有信息就修改获取信息
    @OpenApi
    public Return addVoteUser(CDO cdoRequest) {
        //======== 判断当前是否助业网用户
        Long user_id = null;

        user_id = cdoRequest.getLong("user_id");
        if (user_id == null) {
            user_id = cdoRequest.getLong("user_id_zyw");
        }
        boolean zywUserState = this.verifyWhetherSysUser(user_id);
        if (zywUserState == false) {
            return Return.valueOf("当前账号未认证，请保存正常状态");
        }
        String info_id = cdoRequest.getString("essential_information_id");
        if (info_id == null) {
            return Return.valueOf(-2, "未获取到essential_information_id，基本信息id");
        }
        CDO publicCount = new CDO();
        publicCount.set("essential_information_id", info_id);
        publicCount.set("vote_user_id", user_id);
        int count = voteUserDao.getVoteUserListByConditionCount(publicCount);
        if (count == 0) {
            voteUserDao.addVoteUser(cdoRequest);
        } else {
//          查询获取到id修改信息
            CDO voteUser = voteUserDao.getVoteUser(publicCount);
            if (voteUser != null) {
                cdoRequest.set("id", voteUser.getLong("id"));
                voteUserDao.updateVoteUserById(cdoRequest);
            }
        }
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新投票用户认证数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_zyw:用户id
     *                   - essential_information_id:基本数据id
     *                   - id_card_just:身份证正面
     *                   - id_card_back:身份证反面
     *                   - house_certificate:房产证
     *                   - housing_area:房屋面积
     *                   - building_number:楼号
     *                   - audit_status:认证状态：0、认证成功，1、取消认证；
     *                   - audit_content:取消认证原因
     *                   - preparation_enroll:筹备组是否报名：1已报名，0未报名
     *                   - preparation_time:筹备组报名时间
     *                   - preparation_total:筹备组报名后总票数
     *                   - preparation_status:是否筹备组成员：1是，0否
     *                   - reconsideration_status:召开附议状态：0、待发起 ，1、已经复议，2、未复议
     *                   - reconsideration_time:召开附议时间
     *                   - user_nation:民族
     *                   - user_olitical_outlook:政治面貌
     *                   - user_declaration:个人宣言
     *                   - user_coronal_photograph_img:冠冕照
     *                   - user_consumption_proof_img:消费证明
     *                   - user_other_img:其他材料
     *                   - committee_member_reason:取消原因
     *                   - committee_member_status:是否报名委员：1已报名，0未报名，2取消资格
     *                   - committee_member_total:委员选拔总票数
     *                   - committee_member_total_offline:线下投票人数
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return updateVoteUserById(CDO cdoRequest) {
        String id = cdoRequest.getString("id");
        if(StringUtils.isEmpty(id)) return Return.valueOf(-2, "表决用户主键id不可为空");
        //委员报名取消资格
        String committee_member_status = cdoRequest.getString("committee_member_status");
        //筹备组报名取消资格
        String preparation_enroll = cdoRequest.getString("preparation_enroll");
        CDO voteUserInfo = voteUserDao.getVoteUserById(Integer.parseInt(id));
        if(voteUserInfo == null) return Return.valueOf(-2, "表决用户消息异常");
        if(!StringUtils.isEmpty(committee_member_status)){
            //发送取消委员报名资格消息给业主
            if(committee_member_status.equals("3")){
                String committee_member_reason = cdoRequest.getString("committee_member_reason");//取消原因
                if(StringUtils.isEmpty(committee_member_reason)) return Return.valueOf(-2, "请填写取消原因");
                String remark = "尊敬的"+voteUserInfo.getString("full_name") + "您好！"+"由于（"+committee_member_reason+"）被取消业主委员会报名资格，请在报名截止前，重新提交资料进行报名认证。";
                voteEssentialInformationService.addMessageInfo(remark, voteUserInfo.getString("user_id"), 2);
            }
        }
        if(!StringUtils.isEmpty(preparation_enroll)){
            //发送取消筹备组报名资格消息给业主
            if(preparation_enroll.equals("3")){
                String preparation_cancel_reason = cdoRequest.getString("preparation_cancel_reason");//取消原因
                if(StringUtils.isEmpty(preparation_cancel_reason)) return Return.valueOf(-2, "请填写取消原因");
                String remark = "尊敬的"+voteUserInfo.getString("full_name") + "您好！"+"由于（"+preparation_cancel_reason+"）被取消筹备组报名资格，请在报名截止前，重新提交资料进行报名认证。";
                voteEssentialInformationService.addMessageInfo(remark, voteUserInfo.getString("user_id"), 2);
            }
        }
        int affectedRows = voteUserDao.updateVoteUserById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除投票用户认证数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteUserById(CDO cdoRequest) {
        int affectedRows = voteUserDao.deleteVoteUserById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除投票用户认证数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return deleteVoteUser(CDO cdoRequest) {
        CDO voteUserInfo = voteUserDao.getVoteUserById(cdoRequest.getInteger("id"));
//        int affectedRows = voteUserDao.deleteVoteUser(cdoRequest);
        //修改状态为未报名，不是筹备组人员
        CDO updateUser = new CDO();
        updateUser.set("id",cdoRequest.get("id"));
        updateUser.set("preparation_status",0);
        updateUser.set("preparation_enroll",0);
        voteUserDao.updateVoteUserById(updateUser);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", 1);
        //删除筹备组成员标识参数
        String preparationDel = cdoRequest.getString("preparationDel");
        if(!StringUtils.isEmpty(preparationDel)){
            CDO selectPreparationApplication = new CDO();
            selectPreparationApplication.set("essential_information_id",voteUserInfo.getString("essential_information_id"));
            selectPreparationApplication.set("vote_type",1);
            CDO recordInfo = voteRecordDao.getVoteRecordByCdo(selectPreparationApplication);
            if(recordInfo != null){
                CDO updateRecord= new CDO();
                updateRecord.set("id",recordInfo.getString("id"));
                updateRecord.set("vote_state",0);//1.结束 0.进行中
                //将筹备组报名活动改为未完毕
                voteRecordDao.updateVoteRecordById(updateRecord);
            }
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取投票用户认证数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteUserById(CDO cdoRequest) {
        CDO cdoMapperResult = voteUserDao.getVoteUserById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取投票用户认证数据
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteUser(CDO cdoRequest) {

        CDO cdoMapperResult = voteUserDao.getVoteUser(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }


    @Resource
    VoteRecordDao voteRecordDao;

    /**
     * 根据非空条件，获取投票用户认证数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteUserList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteUserDao.getVoteUserList(cdoRequest);
//       根据身份证号掉年龄性别
        Long user_id = null;
        for (int i = 0; i < cdoMapperResultList.size(); i++) {
            user_id = cdoMapperResultList.get(i).getLong("user_id");
            if (user_id == null) {
                user_id = cdoMapperResultList.get(i).getLong("user_id_zyw");
            }
            CDO userCha = new CDO();
            userCha.set("user_id", user_id);
            CDO sysUserInfoByUserId = voteEssentialInformationDao.getSysUserInfoByUserId(userCha);
            if (sysUserInfoByUserId != null) {
                cdoMapperResultList.get(i).set("user_head_portrait", sysUserInfoByUserId.get("user_head_portrait"));//头像
                cdoMapperResultList.get(i).set("user_front_head_portrait", sysUserInfoByUserId.get("user_front_head_portrait"));//头像、前台使用
            }
            if (user_id != null) {
                CDO personalInformationCdo = voteUserDao.getPersonalInformationCdo(user_id);
                if (personalInformationCdo != null) {
                    String id_card = personalInformationCdo.getString("user_card_code");
                    if (id_card != null) {
                        Map<String, String> birAgeSex = userCardInfoUtil.getBirAgeSex(id_card);
                        cdoMapperResultList.get(i).set("birthday", birAgeSex.get("birthday"));//出生日期
                        cdoMapperResultList.get(i).set("age", birAgeSex.get("age"));//年龄
                        cdoMapperResultList.get(i).set("sexCode", birAgeSex.get("sexCode"));//性别
                    }
                }
            }

//
            Long id = cdoMapperResultList.get(i).getLong("id");
            if (id != null) {
                CDO voteRecCount = new CDO();
//                  `recommend_state` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '推举状态：1、筹备组推举，2、委员推举',
                voteRecCount.set("vote_user_id", id);
                voteRecCount.set("recommend_state", 1);
                int voteRecommendCount = voteRecommendDao.getVoteRecommendCount(voteRecCount);
                if (voteRecommendCount == 0) {
                    cdoMapperResultList.get(i).set("voteYN", true);
                } else {
                    cdoMapperResultList.get(i).set("voteYN", false);
                    cdoMapperResultList.get(i).set("voteYNNumber", voteRecommendCount);
                }
                voteRecCount.set("vote_user_id", id);
                voteRecCount.set("recommend_state", 2);
                int eightVoteRecomCount2 = voteRecommendDao.getVoteRecommendCount(voteRecCount);
                if (eightVoteRecomCount2 == 0) {
                    cdoMapperResultList.get(i).set("eightVoteYN", true);
                } else {
//                    这个·可以单独分开查看投票，写个掉来查询--
                    cdoMapperResultList.get(i).set("eightVoteYN", false);
                    cdoMapperResultList.get(i).set("eightVoteNumber", eightVoteRecomCount2);
                }
            }
        }

//        筹备组成员公示 委员候选人公示 业主大会投票结果公示 业委会职位结果公示

        Long oweRecord = Long.valueOf(1);
        Long essential_information_id = cdoRequest.getLong("essential_information_id");
        if (essential_information_id != null) {
            CDO voteRec = new CDO();
            voteRec.set("essential_information_id", essential_information_id);
            voteRec.set("vote_state", 0);
            CDO voteRecord = voteRecordDao.getVoteRecord(voteRec);
            if (voteRecord != null) {
                String vote_name = voteRecord.getString("vote_name");
                if (vote_name.equals("公开招募筹备组成员")) {
                    oweRecord = Long.valueOf(1);
                } else if (vote_name.equals("委员候选人公示")) {
                    oweRecord = Long.valueOf(2);
                } else if (vote_name.equals("业主大会投票结果公示")) {
                    oweRecord = Long.valueOf(3);
                } else if (vote_name.equals("业委会职位结果公示")) {
                    oweRecord = Long.valueOf(3);
                }
            }

        }


        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        cdoResult.set("oweRecord", oweRecord);
//        int total = voteUserDao.getVoteUserListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取投票用户认证数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author ht
     * @create: 2022-07-08 19:04:49
     */
    @OpenApi
    public Return getVoteUserListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = voteUserDao.getVoteUserListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        int total = voteUserDao.getVoteUserListCount(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
